from PyPDF2 import PdfFileReader, PdfFileWriter


def merge_pdfs(paths, output):
    pdf_writer = PdfFileWriter()
    for path in paths:
        pdf_reader = PdfFileReader(path)
        # a = [0,8,9,10,11,12,13,21,22,23,24,25,26,27,35,36,37,38,39,40,48,49,50,51,52,53]
        a = []
        add(6, 8, a)
        add(14, 16, a)
        # 请输入末尾页码
        last_page = 126
        for page in range(last_page):
            # 将每页添加到writer对象9
            if page not in a:
                pdf_writer.addPage(pdf_reader.getPage(page))

    # 写入合并的pdf
    with open(output, 'wb') as out:
        pdf_writer.write(out)


# 输入要删除的页面的开始页码， 输入要删除页面的结束页码
def add(begin,end, a):
    for i in range(begin-1,end):
        a.append(i)


if __name__ == '__main__':
    # paths = [r'I:\1\1.pdf']
    paths = [r'C:\Users\ASUS\Desktop\【08】米鹏密押3套卷 .pdf']
    merge_pdfs(paths, output=r'I:\1\2.pdf')